<template>
    <div>
        <h1>病房添加</h1>
        <table class="table">
            <tr>
                <td>病房名称</td>
                <td>
                    <input type="text" v-model="data.bname">
                </td>
            </tr>

            <tr>
                <td>病房号</td>
                <td>
                    <input type="text" v-model="data.bnum">
                </td>
            </tr>

            <tr>
                <td>所属科室</td>
                <td>
                    <select v-model="data.kid">
                        <option value="0">请选择科室</option>
                        <option v-for="d in xl" :value="d.kid">{{ d.kname }}</option>
                    </select>
                </td>
            </tr>

            <tr>
                <td>床位总数量</td>
                <td>
                    <input type="text" v-model="data.znum">
                </td>
            </tr>

            <tr>
                <td>状态</td>
                <td>
                    <input type="checkbox" v-model="data.start">打钩为启用,否则为禁用
                </td>
            </tr>

            <tr>
                <td>空闲床数量</td>
                <td>
                    <input type="text" v-model="data.knum">
                </td>
            </tr>

            <tr>
                <td>已满未满状态</td>
                <td>
                    <input type="radio" name="1" :value="false" v-model="data.mstart">未满
                    <input type="radio" name="1" :value="true" v-model="data.mstart">已满
                </td>
            </tr>

            <tr>
                <td></td>
                <td>
                    <input type="button" class="btn btn-success" value="提交" @click="add">
                </td>
            </tr>
        </table>
        <a href="/bfshow">返回病房列表</a>
    </div>
</template>

<script setup lang="ts">
import {ref,onMounted} from 'vue'
import axios from 'axios'
import { useRouter } from 'vue-router';
const router=useRouter()

const data=ref({
  "bnum": "",
  "bname": "",
  "kid": 0,
  "znum": null,
  "mstart": false,
  "start": true,
  "knum": null,
})
//文档就绪
onMounted(()=>{
    bang()
})
//绑定
const xl=ref({})
const bang=()=>{
    axios.get("/api/Ks/GetKsXl").then(res=>{
        xl.value=res.data
    })
}
//添加
const add=()=>{
    if(data.value.bname==""){
        alert('病房名称不能为空');
        return;
    }
    if(data.value.bname>data.value.bname.substring(0,6)){
        alert('病房名称不能超过6个字符');
        return;
    }
    axios.post("/api/Bf/AddBf",data.value).then(res=>{
        if(res.data>0){
            alert('添加成功');
            router.push("/bfshow")
        }
        else{
            alert('添加失败');
        return;
        }
    })
}
</script>

<style scoped>

</style>